// 频道数据的本地缓存键名
const CHANNELS_KEY = 'kuaijian_channels'
type Channels = {
  id: number,
  name: string,
}[]
/**
 * 从本地缓存中获取Channels  信息
 */
export const getChannelsInfo = (): Channels => {
  return JSON.parse(localStorage.getItem(CHANNELS_KEY) || '{}')
}

/**
 * 将 Channels 信息存入缓存
 * @param {Object} tokenInfo 从后端获取到的 Token 信息
 */
export const setChannelsInfo = (tokenInfo: Channels) => {
  localStorage.setItem(CHANNELS_KEY, JSON.stringify(tokenInfo))
}

/**
 * 删除本地缓存中的 Channels 信息
 */
export const removeChannelsInfo = () => {
  localStorage.removeItem(CHANNELS_KEY)
}
